package com.cuput.partybuilding.loginbundle;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.cuput.partybuilding.loginbundle.databinding.ActivityLoginBinding;
import com.cuput.partybuilding.loginbundle.presenter.LoginPresenter;
import com.cuput.partybuilding.publiclibrary.base.BaseActivity;
import com.cuput.partybuilding.publiclibrary.bean.User;
import com.taobao.android.ActivityGroupDelegate;

public class LoginActivity extends BaseActivity<LoginPresenter> {
    private ActivityLoginBinding activityLoginBinding;
    private LoginViewController loginViewController;
    private ActivityGroupDelegate mActivityDelegate;
    private ViewGroup mActivityGroupContainer;
    private TextView loginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        activityLoginBinding = DataBindingUtil.setContentView(this, R.layout.activity_login);
        loginViewController = new LoginViewController();
        activityLoginBinding.setLoginViewController(loginViewController);
//        mActivityDelegate = new ActivityGroupDelegate(this, savedInstanceState);
//        mActivityGroupContainer = (ViewGroup) findViewById(R.id.content);
        initView();
        initListener();
    }

    @Override
    public LoginPresenter getPresenter() {
        return new LoginPresenter(this);
    }

    private void initView() {
        loginBtn = (TextView) findViewById(R.id.loginBtn);
    }

    private void initListener() {
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 校验登录是否为空
                if (mPresenter.isLoginEmpty(loginViewController.getUser())) {

                    Toast.makeText(LoginActivity.this, getString(LoginActivity.this, R.string.please_enter_phone_number_and_password), Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent();
                    intent.setClassName(getBaseContext(),"com.cuput.partybuilding.contact.ContactActivity");
                    startActivity(intent);
                }
            }
        });
    }

    private void switchToActivity(String key,String activityName){
        Intent intent = new Intent();
        intent.setClassName(getBaseContext(),activityName);
        mActivityDelegate.startChildActivity(mActivityGroupContainer,key,intent);
    }

    private String getString(Context context, int stringId) {
        return context.getString(stringId);
    }

    public class LoginViewController {
        private User user = new User();

        public User getUser() {
            return user;
        }

        public void setUser(User user) {
            this.user = user;
        }
    }
}
